<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1 th:if=" ${ProjectCostModel.kind} == 0">
        预算数据—下料计划工时明细
    </h1>
    <h1 th:if=" ${ProjectCostModel.kind} == 1">
        核算数据—下料确认工时明细
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <input  name="kind" type="hidden" th:value="${ProjectCostModel.kind}">
                        <input  name="designType" type="hidden" th:value="${ProjectCostModel.designType}">
                        <input  name="inputId" type="hidden" th:value="${ProjectCostModel.inputId}">
                        <input  name="partName" type="hidden" th:value="${ProjectCostModel.partName}">
                        <input name="costKind" type="hidden" th:value="${ProjectCostModel.costKind}">
                        <input name="kbId" type="hidden" th:value="${ProjectCostModel.fkId}">
                        <input name="code" type="hidden" th:value="${ProjectCostModel.code}">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>项目编号：</label>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:text="${ProjectCostModel.code}"></span>
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>项目名称：</label>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:text="${ProjectCostModel.name}"></span>
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>项目数量：</label>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:text="${ProjectCostModel.num}"></span>
                                </div>
                            </div>
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>设备部分：</label>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:text="${ProjectCostModel.partName}"></span>
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;专业：</label>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:if="${ProjectCostModel.designType==1}">机械</span>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:if="${ProjectCostModel.designType==2}">自动化</span>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px;text-align: center;"
                                          th:if="${ProjectCostModel.designType==3}">流体</span>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-top: 5px;">
                                    <label>设计类别：</label>
                                    <span class="form-control"
                                          style="border:none;border-bottom: solid 1px #eee; width: 300px; text-align: center;"
                                          th:text="${ProjectCostModel.projectClassifyName}"></span>
                                </div>
                                <input name="kind" type="hidden" th:value="${ProjectCostModel.kind}">
                                <input name="designType" type="hidden" th:value="${ProjectCostModel.designType}">
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar1" class="row">
                    <a style="margin-right: 10px"
                       id="btn_add1" class="btn btn-info">
                        人工工时添加
                    </a>
                    <a href="javascript:void(0);"
                       style="margin-right: 10px"
                       class="btn btn-danger"
                       onclick="delManHour()">
                        <span class="Bold">数据清空</span>
                    </a>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table1"
                           style="table-layout: fixed;word-break:break-all; word-wrap:break-word;"></table>
                </div>
                <div id="toolbar2" class="row">
                    <a style="margin-right: 10px"
                       id="btn_add2" class="btn btn-info">
                        辅材信息添加
                    </a>
                    <a href="javascript:void(0);"
                       style="margin-right: 10px"
                       class="btn btn-danger"
                       onclick="delMat()">
                        <span class="Bold">数据清空</span>
                    </a>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table2"
                           style="table-layout: fixed;word-break:break-all; word-wrap:break-word;"></table>
                </div>
                <!--<form id="queryForm2" onsubmit="return false;">-->
                    <!--<input id="code" name="code" type="hidden" th:value="${ProjectCostModel.code}">-->
                    <!--<input id="name" name="name" type="hidden" th:value="${ProjectCostModel.name}">-->
                    <!--<input id="num" name="num" type="hidden" th:value="${ProjectCostModel.num}">-->
                    <!--<input id="demander" name="demander" type="hidden" th:value="${ProjectCostModel.demander}">-->
                    <!--<input id="address" name="address" type="hidden" th:value="${ProjectCostModel.address}">-->
                    <!--<input id="projectClassify" name="projectClassifyNG" type="hidden"-->
                           <!--th:value="${ProjectCostModel.projectClassify}">-->
                <!--</form>-->
            </div>
        </div>
    </div>
    <!--添加人工工时模态框-->
    <div class="modal fade" id="modal-add1">
        <div class="modal-dialog" style="width:900px">
            <div class="modal-content" style="height:430px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">下料工时编辑</h4>
                </div>
                <div class="modal-body" style="height: 60%">
                    <form id="invForm1" class="form-horizontal" style="margin-right: 70px">
                        <div class="col-md-12" style="font-weight: bold">
                            <input name="mName" value="1" type="hidden">
                            <input id="kind" name="kind" type="hidden">
                            <input id="designType" name="designType" type="hidden">
                            <input id="fkInputId"  name="inputId" type="hidden">
                            <input id="partName"  name="partName" type="hidden">
                            <input id="costKind"  name="costKind" type="hidden">
                            <input id="fkId"   name="kbId" type="hidden">
                            <input id="manId"  name="manId" type="hidden">
                            <input name="code" type="hidden">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="manHours">人工工时类别</label>
                                <div class="col-sm-10">
                                    <input type="text" id="manHours" name="manHours"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="manNum">数量</label>
                                <div class="col-sm-10">
                                    <input type="text" id="manNum" name="manNum"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="manUnit">单位</label>
                                <div class="col-sm-10">
                                    <input type="text" id="manUnit" name="manUnit"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="manRemark">备注</label>
                                <div class="col-sm-10">
                                    <input type="text" id="manRemark" name="manRemark"
                                           class="form-control">
                                </div>
                            </div>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-info file-contract btn-file" id="btn-commit1">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
    <!--添加辅材信息模态框-->
    <div class="modal fade" id="modal-add2">
        <div class="modal-dialog" style="width:900px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">辅材信息编辑</h4>
                </div>
                <form id="invForm2" class="form-horizontal" style="margin-right: 70px">
                    <div class="modal-header" style="height: 300px">
                        <div class="col-md-12" style="font-weight: bold">
                            <input name="mName" value="2" type="hidden" >
                            <input id="mKind" name="kind" type="hidden">
                            <input id="mDesignType" name="designType" type="hidden">
                            <input id="mFkInputId" name="inputId" type="hidden">
                            <input id="" name="partName" type="hidden">
                            <input id="mCostKind" name="mCostKind" type="hidden">
                            <input id="mFkId" name="kbId" type="hidden">
                            <input id="mid" name="mid" type="hidden">
                            <input name="code" type="hidden">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="matName">辅材名称</label>
                                <div class="col-sm-10">
                                    <input type="text" id="matName" name="matName"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="matNum">辅材用量</label>
                                <div class="col-sm-10">
                                    <input type="text" id="matNum" name="matNum"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="matUnit">单位</label>
                                <div class="col-sm-10">
                                    <input type="text" id="matUnit" name="matUnit"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label no-padding-right" for="matRemark">备注</label>
                                <div class="col-sm-10">
                                    <input type="text" id="matRemark" name="matRemark"
                                           class="form-control">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-info file-contract btn-file" id="btn-commit2">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table1;
    var table2;


    /**
     * 工时删除
     * @param manId
     *
     */
    function manpowerErase(manId) {
        js.modal.confirm("确认删除该条人工工时信息吗？", function () {
            js.post({
                url: ctx + 'dataEntry/cutting/delManHour',
                data: {
                    manId: manId
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table1);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        })
    }

    /**
     * 辅材删除
     * @param mid
     * */
    function materialExpurgate(mid) {
        js.modal.confirm("确认删除该条辅材信息吗？", function () {
            js.post({
                url: ctx + 'dataEntry/cutting/delMaterial',
                data: {
                    mid: mid
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table2);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
    }
    /**
     * 人工工时数据清空
     *
     * */
    function delManHour() {
        js.modal.confirm("确定清空所有外购件计划数据吗？", function () {
            js.submit({
                data: new FormData($("#queryForm")[0]),
                url: ctx + 'dataEntry/cutting/delManHourAll',
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table1);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
    }
    /**
     * 辅材信息数据清空
     *
     * */
    function delMat() {
        js.modal.confirm("确定清空所有外购件计划数据吗？", function () {
            js.submit({
                data: new FormData($("#queryForm")[0]),
                url: ctx + 'dataEntry/cutting/delMatAll',
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table2);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            });
        });
    }

    /**
     * 工时编辑
     * @param manId
     */
    function manpowerEdit(manId) {

        js.post({
            url: ctx + "dataEntry/cutting/oneManpowerTime",
            data: {
                manId: manId
            },
            // data: new FormData($("#queryForm")[0]),
            success: function (result) {
                $("#invForm1").fillData(result);
                $("#manId").val(manId);
                $("#invForm1 input[name='mName']").val(1);
                js.modal.open("modal-add1");
                js.modal.closeLoading();
            }
        })
    }

    /**
     * 辅材编辑
     * @param mid
     */
    function materialRedact(mid) {
        $("#mid").val(mid);
        js.post({
            url: ctx + "dataEntry/cutting/oneMaterial",
            data: {
                mid: mid
            },
            // data: new FormData($("#queryForm")[0]),
            success: function (result) {
                $("#invForm2").fillData(result);
                $("#mid").val(mid);
                $("#invForm2 input[name='mName']").val(2);
                js.modal.open("modal-add2");
                js.modal.closeLoading();
            }
        })
    }

    $(function () {
        //加载列表数据,下料工时类别
        table1 = js.table.init({
            id: 'bootstrap-table1',
            url: ctx + "dataEntry/cutting/manpower",
            toolbar: 'toolbar1',
            showColumns: false,
            showExport: false,
            pagination: false,
            pageSize: 3,
            striped: false,
            columns: [
                {
                    title: '序号', field: 'invId', width: '60',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '下料工时类别', field: 'manHours', width: '300'},
                {title: '数量', field: 'manNum', width: '120'},
                {title: '单位', field: 'manUnit', width: '120'},
                {title: '备注', field: 'manRemark', width: '300'},
                {title: '填报人', field: 'manInputUser', width: '120'},
                {title: '填报时间', field: 'manEditDate', width: '120'},
                {title: '接收状态', field: 'manReceiveFlag', width: '120',
                    formatter: function (value, row, index, field) {
                        if (value == 0) {
                            return '未接收';
                        } else if (value == 1) {
                            return '已接收';
                        }
                    }},
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push("<a class='btn btn-warning btn-xs'  href='javascript:void(0);' onclick='manpowerEdit(" + row.manId + ")'>编辑</a>");
                        actions.push("<a class='btn btn-danger btn-xs'  href='javascript:void(0);' onclick='manpowerErase(" + row.manId + ")'>删除</a>");
                        return actions.join('');
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table1);
        });
        //加载列表数据,辅材列表
        table2 = js.table.init({
            id: 'bootstrap-table2',
            url: ctx + "dataEntry/cutting/material",
            toolbar: 'toolbar2',
            showColumns: false,
            showExport: false,
            pagination: false,
            pageSize: 3,
            striped: false,
            columns: [
                {
                    title: '序号', field: 'invId', width: '60',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '主要辅材类别', field: 'matName', width: '300'},
                {title: '辅材用量', field: 'matNum', width: '120'},
                {title: '单位', field: 'matUnit', width: '120'},
                {title: '备注', field: 'matRemark', width: '300'},
                {title: '填报人', field: 'matInputUser', width: '120'},
                {title: '填报时间', field: 'matEditDate', width: '120'},
                {title: '接收状态', field: 'matReceiveFlag', width: '120',
                    formatter: function (value, row, index, field) {
                        if (value == 0) {
                            return '未接收';
                        } else if (value == 1) {
                            return '已接收';
                        }
                    }},
                {
                    title: '操作',
                    formatter: function (value, row, index) {

                        var actions = [];
                        actions.push("<a class='btn btn-warning btn-xs'  href='javascript:void(0);' onclick='materialRedact(" + row.mid + ")'>编辑</a>");
                        actions.push("<a class='btn btn-danger btn-xs'  href='javascript:void(0);' onclick='materialExpurgate(" + row.mid + ")'>删除</a>");
                        return actions.join('');
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table2);
        });

        /**
         * 打开人工工时添加模态框重新赋值
         */
        $("#btn_add1").on('click', function () {
            $("#invForm1 input[name='mName']").val(1);
            // $("#invForm1[name='manId']").val($("#queryForm[name='manId']").val());
            $("#invForm1 input[name='kind']").val($("#queryForm input[name='kind']").val());
            $("#invForm1 input[name='designType']").val($("#queryForm input[name='designType']").val());
            $("#invForm1 input[name='inputId']").val($("#queryForm input[name='inputId']").val());
            $("#invForm1 input[name='partName']").val($("#queryForm input[name='partName']").val());
            $("#invForm1 input[name='costKind']").val($("#queryForm input[name='costKind']").val());
            $("#invForm1 input[name='kbId']").val($("#queryForm input[name='kbId']").val());
            $("#invForm1 input[name='code']").val($("#queryForm input[name='code']").val());
            js.modal.open("modal-add1");
        });
        /**
         * 打开辅材添加模态框重新赋值
         */
        $("#btn_add2").on('click', function () {
            $("#invForm2 input[name='mName']").val(2);
            // $("#invForm2[name='mid']").val($("#queryForm[name='mid']").val());
            $("#invForm2 input[name='kind']").val($("#queryForm input[name='kind']").val());
            $("#invForm2 input[name='designType']").val($("#queryForm input[name='designType']").val());
            $("#invForm2 input[name='inputId']").val($("#queryForm input[name='inputId']").val());
            $("#invForm2 input[name='partName']").val($("#queryForm input[name='partName']").val());
            $("#invForm2 input[name='mCostKind']").val($("#queryForm input[name='costKind']").val());
            $("#invForm2 input[name='kbId']").val($("#queryForm input[name='kbId']").val());
            $("#invForm2 input[name='code']").val($("#queryForm input[name='code']").val());
            js.modal.open("modal-add2");
        });
        /**
         * 人工工时模态框保存
         */
        $("#btn-commit1").on('click', function () {
            js.submit({
                url: ctx + "dataEntry/cutting/manpowerSave",
                data: new FormData($("#invForm1")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table1);
                        js.modal.hide("modal-add1");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /**
         * 辅材信息模态框保存
         */
        $("#btn-commit2").on('click', function () {

            js.submit({

                url: ctx + "dataEntry/cutting/manpowerSave",
                data: new FormData($("#invForm2")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        $("#returnId").val(result.data);
                        js.modal.success(result.msg);
                        js.table.refresh(table2);
                        js.modal.hide("modal-add2");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /** 导入模态框隐藏事件，重置表单 */
        js.modal.hideEvent("modal-add1", function () {
            js.reset("invForm1");
        })
        js.modal.hideEvent("modal-add2", function () {
            js.reset("invForm2");
        })
    });
</script>
</body>
</html>